#include "../h/scheme.h"
#include <stdlib.h>
#include <string.h>

void *autoMalloc(int size){
	return malloc(size);
}

SOBVoid *makeSchemeVoid(){
	SOBVoid *sob;
	sob->type = SCHEME_VOID;
	return sob;
}

SOBInt *makeSchemeInt(int n){
	SOBInt *sob;
	sob->type = SCHEME_INT;
	sob->value = n;
	return sob;
}

SOBChar *makeSchemeChar(char c){
	SOBChar *sob;
	sob->type = SCHEME_CHAR;
	sob->value = c;
	return sob;
}

SOBBool *makeSchemeBool(BoolType b){
	SOBBool *sob;
	sob->type = SCHEME_BOOL;
	sob->value = b;
	return sob;
}

SOBString *makeSchemeString(int n, char *s){
	SOBString *sob;
	sob->type = SCHEME_STRING;
	sob->length = n;
	sob->value = s;
	return sob;
}

SOBString *makeSchemeStringFromCString(char *s){
	SOBString *sob;
	sob->type = SCHEME_STRING;
	sob->length = strlen(s);
	sob->value = (char *)autoMalloc(1 + sob->length);
	strcpy(sob->value, s);
	return sob;
}

SOBNil *makeSchemeNil(){
	SOBNil *sob;
	sob->type = SCHEME_NIL;
	return sob;
}

SOBPair *makeSchemePair(SchemeObject *car, SchemeObject *cdr){
	SOBPair *sob;
	sob->type = SCHEME_PAIR;
	sob->car = car;
	sob->cdr = cdr;
	return sob;
}

SOBVector *makeSchemeVectorInit(int n, SchemeObject *initSob){
	SOBVector *sob;
	int i;
	sob->type = SCHEME_VECTOR;
	sob->vec = (SchemeObject **)autoMalloc(n*sizeof(SchemeObject *));
	for (i = 0; i < n; i++){
		sob->vec[i] = initSob;
	}
	return sob;
}

void push(void *x)
{
  //ASSERT_ALWAYS(sp < MAX_STACK_SIZE);
  stack[sp++] = x;
}

void *pop()
{
  //ASSERT_ALWAYS(sp > 0);
  return stack[--sp];
}

